package com.example.interrupt;

public class PrintABCLoop {
    // todo  三个线程循环打印ABC
    public static final Object lock = new Object();

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            synchronized (lock) {
                while (true) {
                    System.out.print("A");
                    try {
                        lock.wait();
                        //lock.notify();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        });
        Thread t2 = new Thread(() -> {
            synchronized (lock) {
                while (true) {
                    System.out.print("B");
                    try {
                        lock.wait();
                        //lock.notify();
                    } catch (/*Interrupted*/Exception e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        });
//        Thread t3 = new Thread(() -> {
//        });
        t1.start();
        t2.start();
    }
}
